<template>
	<div id="defeat">
		<component-title :title-text="times[time].text+'跑'+(defeatData[type-1].number>=0?'赢':'输')+defeatData[type-1].text+'指数'"></component-title>
		<div v-show="module==0">
			<div class="defeatDetails" :style="{color:defeatData[type-1].number>=0?'#eb333b':'#1aae52'}" v-text="(defeatData[type-1].number*100).toFixed(2)+'%'"></div>
			<ul class="chartDefeat">
				<li class="dataBar" v-for="item in defeatData">
					<div class="barName" v-text="'跑'+(item.number>=0?'赢':'输')+item.text"></div>
					<div class="barContainer" :style="{borderColor:item.number>=0?'#eb333b':'#1aae52'}">
						<div class="circleLeft" :style="{background:item.number>=0?'#eb333b':'#1aae52'}"></div>
						<div class="barContent" :style="{width:Math.abs(item.number)*100*widthRate+'%',background:item.number>=0?'#eb333b':'#1aae52'}"></div>
						<div class="circleRight" :style="{background:item.number>=0?'#eb333b':'#1aae52'}"></div>
					</div>
					<div class="barNumber" :style="{color:item.number>=0?'#eb333b':'#1aae52'}" v-text="(item.number*100).toFixed(2)+'%'"></div>
				</li>
			</ul>
		</div>
		<return-error v-show="module==1"></return-error>
		<return-empty v-show="module==2"></return-empty>
	</div>
</template>
<script>
	import Title from '@/components/Title'
	import RemoteDAO from '@/common/remoteDAO'
	import constant from '@/common/constant'

	export default{
		props:{
			time: {
				type: Number
			},
			type: {
				type: Number
			},
			defeatData: {
				type: Array,
				default: []
			},
			module:{
				type:Number
			}
		},
		data () {
			return {
				times:[
					{
					name:'today',
					text:'今日',
					num:'1',
					monthNum:1
					},
					{
					name: 'curmonth',
					text: '本月',
					num:'30',
					monthNum:1
					},
					{
					name: 'quarter',
					text: '近三个月',
					num:'90',
					monthNum:3
					},
					{
					name: 'halfyear',
					text: '近半年',
					num:'180',
					monthNum:6
					},
					{
					name: 'year',
					text: '今年',
					num:'365',
					monthNum:12
					},
					{
					name: '2016',
					text: '2016',
					num:'366',
					monthNum:12
					}
				]
			}
		},
		computed:{
			widthRate:function(){
				let originArr=[]
				this.defeatData.forEach(value=>{
					originArr.push(Math.abs(value.number)*100)
				})
				let maxNumber=Math.max.apply(null,originArr)
				if(maxNumber<80){
					return 80/maxNumber
				}
				else{
					return 1
				}
			}
		},
		created(){
			// console.log(this.defeatData)
		},
		components:{
			'component-title':Title
		}
	}
</script>
<style scoped>
	#defeat{
		background: #fff;
		padding: 40px 0;
	}
	.defeatDetails{
		height: 60px;
		margin-top: 20px;
		font-size: 60px;
		line-height: 60px;
		color: #1ea241;
		text-align: center;
	}
	.charts{
		padding: 0 30px;
	}
	.chartDefeat{
		margin-top:14px;
	}
	.dataBar{
		margin-top: 20px;
		height: 40px;
		padding: 5px 40px 5px 30px;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.dataBar .barName{
		font-size: 28px;
		color: #555;
		padding-right: 20px;
	}
	.barContainer{
		height: 30px;
		background: #f1f1f1;
		box-sizing: border-box;
		border-radius: 15px;
		overflow: hidden;
		flex-grow: 1;
	}
	.circleLeft{
		width: 15px;
		height: 30px;
		border-radius: 15px 0 0 15px;
		float: left;
	}
	.barContent{
		height: 100%;
		float: left;
		transition: 0.5s;
	}
	.circleRight{
		width: 15px;
		height: 30px;
		border-radius: 0 15px 15px 0;
		float: left;
	}
	.barNumber{
		width: 96px;
		font-size: 24px;
		color: #555;
		text-align: right;
	}
</style>
